package org.edu.modules.sxjy.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.Objects;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.common.system.base.controller.BaseController;
import org.edu.modules.sxjy.entity.VeCommon;
import org.edu.modules.sxjy.entity.VeSumup;
import org.edu.modules.sxjy.service.IVeSumupService;
import org.edu.modules.sxjy.utils.PageResponseResult;
import org.edu.modules.sxjy.vo.VeSumupAddVo;
import org.edu.modules.sxjy.vo.VeSumupInfoVo;
import org.edu.modules.sxjy.vo.VeSumupVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags={"实习总结"})
@RestController
@RequestMapping({"/sxjy/veSumup"})
@Component
@ApiSort(60)
public class VeSumupController
        extends BaseController<VeSumup, IVeSumupService>
{
    private static final Logger log = LoggerFactory.getLogger(VeSumupController.class);
    @Autowired
    private IVeSumupService veSumupService;

    @AutoLog("实习总结-查询实习总结")
    @ApiOperation(value="查询", notes="实习总结-查询实习总结")
    @GetMapping({"/selectAll"})
    public PageResponseResult selectAll(VeSumupVo veSumupVo, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, VeCommon veCommon)
    {
        Integer startLine = Integer.valueOf((pageNo.intValue() - 1) * pageSize.intValue());
        List<VeSumupVo> veSumupList = this.veSumupService.selectAll(veSumupVo, startLine, pageSize, veCommon);
        int total = this.veSumupService.getSumPage(veSumupVo, veCommon);
        if ((Objects.isNull(veSumupList)) && (veSumupList.size() <= 0)) {
            return new PageResponseResult(Integer.valueOf(1), 1, 0, Result.OK());
        }
        double totals = total;
        double pageSizes = pageSize.intValue();
        double totalPage = Math.ceil(totals / pageSizes);
        return new PageResponseResult(pageNo, (int)totalPage, total, Result.OK(veSumupList));
    }

    @AutoLog("实习总结-查看详细信息")
    @ApiOperation(value="查看详细信息", notes="实习总结-查看详细信息")
    @GetMapping({"/selectOneInfo"})
    public Result<?> selectOneInfo(int id, String userType, String userId)
    {
        VeSumupInfoVo veSumupInfoVo = this.veSumupService.getOneInfo(id, userType, userId);
        if (veSumupInfoVo == null) {
            return Result.OK();
        }
        return Result.OK(veSumupInfoVo);
    }

    @AutoLog("实习总结-提交总结")
    @ApiOperation(value="提交总结", notes="实习总结-提交总结")
    @PostMapping({"/addSumup"})
    public Result<?> addSumup(@RequestBody VeSumupAddVo veSumupAddVo)
    {
        return this.veSumupService.addSumup(veSumupAddVo);
    }
}
